/* GUI CONVERTED from sosorpa1.p (converter v1.75) Fri Feb  2 01:27:18 2001 */
/* sosorpa1.p - -SHIPMENT HISTORY BY PART                               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*K0L9*/
/*V8:ConvertMode=Report                                        */
/* REVISION: 5.0          LAST EDIT: 06/21/89   BY: MLB *B130* */
/* REVISION: 6.0      LAST MODIFIED: 10/19/90   BY: afs *D112* */
/* REVISION: 6.0      LAST MODIFIED: 12/02/90   BY: afs *D237* */
/* REVISION: 6.0      LAST MODIFIED: 03/08/91   BY: afs *D408* */
/* REVISION: 7.2      LAST MODIFIED: 05/11/95   BY: jym *F0RM* */
/* REVISION: 7.3      LAST MODIFIED: 04/10/96   BY: jzw *G1P6* */
/* REVISION: 8.6      LAST MODIFIED: 10/02/97   BY: ckm *K0L9**/
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 07/05/98   BY: *L024* Sami Kureishy*/
/* REVISION: 9.1      LAST MODIFIED: 06/29/00   BY: *N0DX* Rajinder Kamra */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* myb            */
/* REVISION: 9.1      LAST MODIFIED: 08/04/00   BY: *N0WC* BalbeerS Rajput */



/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdeclre.i}
/*N0WC*/ {cxcustom.i "SOSORPA1.P"}
/*N0DX*/ {gplabel.i}

         /* ********** Begin Translatable Strings Definitions ********* */

/*N0DX
 *        &SCOPED-DEFINE sosorpa1_p_1 "Report Total: "
 *        /* MaxLen: Comment: */
 *
 *        &SCOPED-DEFINE sosorpa1_p_2 "Total Margin"
 *        /* MaxLen: Comment: */
 *
 *        &SCOPED-DEFINE sosorpa1_p_3 "   Total Qty"
 *        /* MaxLen: Comment: */
 *
 *        &SCOPED-DEFINE sosorpa1_p_4 " Total Sales"
 *        /* MaxLen: Comment: */
 *N0DX*/

          &SCOPED-DEFINE sosorpa1_p_5 "Gross Margin"
          /* MaxLen: Comment: */

         /* ********** End Translatable Strings Definitions ********* */

/*K0L9*/ {wbrp02.i}

         define shared variable part like pt_part.
         define shared variable part1 like pt_part.
         define shared variable cust like tr_addr.
         define shared variable cust1 like tr_addr.
/*D002*/ define shared variable site like tr_site.
/*D002*/ define shared variable site1 like tr_site.
         define shared variable buyer like pt_buyer.
         define shared variable prod_line like pt_prod_line.
         define shared variable ptgroup like pt_group.
         define shared variable part_type like pt_part_type.
         define shared variable vendor like pt_vend.
         define shared variable pm_code like pt_pm_code.
         define shared variable sdate as date extent 14.
         define variable salesqty as decimal extent 14 format "->>>>>>>9".
         define variable salesdol as decimal extent 14 format "->>>>>>>9".
         define variable salesprft as decimal extent 14 format "->>>>>>>9".
         define variable due_date like tr_effdate.
         define variable i as integer.
         define shared variable num_intervals as integer initial 13 format "9".
         define variable tot_qty as decimal format "->>>>>>>>>>9".
         define variable tot_dol as decimal format "->>>>>>>>>>9".
         define variable tot_prft as decimal format "->>>>>>>>>>9".
         define variable first_part like mfc_logical.
         define shared
          variable show_profit like mfc_logical label {&sosorpa1_p_5} initial "yes".
         define shared
          variable base_rpt like so_curr.
/*G1P6*  initial "Base" format "x(4)". */
         define variable base_price like tr_price.
/*D237*/ define variable base_cost like tr_price.
/*D112*/ define shared variable round_1000 like mfc_logical.
/*L024*/ define variable mc-error-number like msg_nbr no-undo.

/*N0DX*/ define variable disp_char1 as character      no-undo.
/*N0DX*/ define variable disp_char2 as character      no-undo.
/*N0DX*/ define variable disp_char3 as character      no-undo.
/*N0DX*/ define variable disp_char4 as character      no-undo.

/*N0DX START ADD*/
   assign disp_char1 = getTermLabel("REPORT_TOTAL",33) + ": ":U
          disp_char2 = getTermLabel("TOTAL_MARGIN",12)
          disp_char3 = getTermLabelRt("TOTAL_QTY",12)
          disp_char4 = getTermLabel("TOTAL_SALES",12).
/*N0DX END ADD*/


   display
/*N0DX space(120) {&sosorpa1_p_3} skip */
/*N0DX*/ space(120) disp_char3 format "x(12)" skip
   sdate[2] space(2) sdate[3] space(2)
   sdate[4] space(2) sdate[5] space(2)
   sdate[6] space(2) sdate[7] space(2)
   sdate[8] space(2) sdate[9] space(2)
   sdate[10] space(2) sdate[11] space(2)
   sdate[12] space(2) sdate[13] space(2)
/*N0DX  {&sosorpa1_p_4} skip */
/*N0DX*/  disp_char4 format "x(12)" skip
   sdate[3] - 1 space(2) sdate[4] - 1 space(2)
   sdate[5] - 1 space(2) sdate[6] - 1 space(2)
   sdate[7] - 1 space(2) sdate[8] - 1 space(2)
   sdate[9] - 1 space(2) sdate[10] - 1 space(2)
   sdate[11] - 1 space(2) sdate[12] - 1 space(2)
   sdate[13] - 1 space(2) sdate[14] - 1 space(2)
/*N0DX {&sosorpa1_p_2} skip */
/*N0DX*/ disp_char2 format "x(12)"  skip
   "--------- --------- --------- --------- --------- --------- ---------"
   "--------- --------- --------- --------- --------- ------------" skip
   with frame b no-labels width 132 page-top no-box STREAM-IO /*GUI*/ .

   /* view frame phead. */

   for each pt_mstr where (pt_part >= part and pt_part <= part1)
   and (pt_buyer = buyer or buyer = "")
   and (pt_prod_line = prod_line or prod_line = "")
   and (pt_group = ptgroup or ptgroup = "")
   and (pt_part_type = part_type or part_type = "")
   and (pt_vend = vendor or vendor = "")
   and (pt_pm_code = pm_code or pm_code = "") no-lock
   with frame b width 132 no-box:

      /* INITIALIZE VARIABLES */
      do i = 1 to num_intervals + 1:
     salesqty[i] = 0.
     salesdol[i] = 0.
     salesprft[i] = 0.
      end.

      /* CALCULATE SHIPMENTS   FOR EACH INTERVAL */
      tot_qty = 0.
      tot_dol = 0.
      tot_prft = 0.
      first_part = yes.
/*N0WC*/ {&SOSORPA1-P-TAG1}
      for each tr_hist where tr_part = pt_part
      and (tr_type = "ISS-SO" or tr_type = "RCT-SOR")
      and (tr_addr >= cust and tr_addr <= cust1)
/*D002*/ and (tr_site >= site and tr_site <= site1)
    AND (LOOKUP(tr_site,GLOBAL_user_site) > 0)      /*fdn*/
      and (tr_effdate >= sdate[2] and tr_effdate < sdate[14])
/*G1P6*/ and ((base_rpt = "")
     or (tr_curr = base_rpt))
      no-lock
      use-index tr_part_eff:
/*N0WC*/ {&SOSORPA1-P-TAG2}
     if first_part then do:
        if page-size - line-counter < 4 then page.
        display pt_part pt_desc1 pt_desc2 pt_um skip
        with frame bb no-labels width 132 STREAM-IO /*GUI*/ .
        first_part = no.
     end.
/*F0RM*/ if tr_ship_type <> " " then
/*F0RM*/   assign base_cost = tr_mtl_std + tr_lbr_std + tr_bdn_std +
/*F0RM*/                      tr_ovh_std + tr_sub_std.
/*F0RM*/ else assign base_cost  = - tr_gl_amt / tr_qty_loc.

/*G1P6*/    if base_rpt <> ""
        and tr_curr <> base_curr then do:
/*L024* base_price = tr_price   * tr_ex_rate.*/
/*L024*/{gprunp.i "mcpl" "p" "mc-curr-conv"
                     "(input base_curr,
                       input tr_curr,
                       input tr_ex_rate2,
                       input tr_ex_rate,
                       input tr_price,
                       input false,
                       output base_price,
                       output mc-error-number)"}.
/*L024*/ if mc-error-number <> 0 then do:
/*L024*/    {mfmsg.i mc-error-number 2}
/*L024*/ end.

/*L024* *F0RM* base_cost  = base_cost * tr_ex_rate.*/
/*L024*/{gprunp.i "mcpl" "p" "mc-curr-conv"
                     "(input base_curr,
                       input tr_curr,
                       input tr_ex_rate2,
                       input tr_ex_rate,
                       input base_cost,
                       input false,
                       output base_cost,
                       output mc-error-number)"}.
/*L024*/ if mc-error-number <> 0 then do:
/*L024*/    {mfmsg.i mc-error-number 2}
/*L024*/ end.

     end.
     else do:
        base_price = tr_price.
/*D408*     base_cost  = tr_mtl_std + tr_lbr_std + tr_ovh_std +  */
/*D408*      tr_sub_std + tr_bdn_std.                            */
/*F0RM /*D408*/    base_cost  = - tr_gl_amt / tr_qty_loc.        */
     end.
     due_date = tr_effdate.
     tot_qty = tot_qty - tr_qty_loc.
     tot_dol = tot_dol - (base_price * tr_qty_loc).
     tot_prft = tot_prft - ((base_price - base_cost) * tr_qty_loc).
     do i = num_intervals + 1 to 1 by -1:
        if due_date >= sdate[i] then do:
           salesqty[i] = salesqty[i] - tr_qty_loc.
           salesdol[i] = salesdol[i] - (base_price * tr_qty_loc).
           salesprft[i] = salesprft[i] - ((base_price - base_cost)
         * tr_qty_loc).
           leave.
        end.
     end.
      end.

      if not first_part then do:

     if round_1000 then do:
        do i = 1 to num_intervals + 1:
           salesdol[i] = round(salesdol[i] / 1000, 0).
           if show_profit then
          salesprft[i] = round(salesprft[i] / 1000, 0).
        end.
        tot_dol = round(tot_dol / 1000, 0).
        if show_profit then
           tot_prft = round(tot_prft / 1000, 0).
     end.
     accumulate salesqty(total).
     accumulate salesdol(total).
     accumulate tot_qty(total).
     accumulate tot_dol(total).
     if show_profit then do:
        accumulate salesprft(total).
        accumulate tot_prft(total).
     end.

     display salesqty[2 for 12] tot_qty skip
      salesdol[2 for 12] tot_dol
      with frame cc no-labels no-box width 132 STREAM-IO /*GUI*/ .
     if show_profit then
        display skip salesprft[2 for 12] tot_prft
         with frame cc no-labels no-box width 132 STREAM-IO /*GUI*/ .

      end.

      
/*GUI*/ {mfguirex.i } /*Replace mfrpexit*/

   end.

   display skip(1)
/*N0DX   {&sosorpa1_p_1} skip */
/*N0DX*/ disp_char1 format "x(35)" skip
   accum total salesqty[2] format "->>>>>>>9"
   accum total salesqty[3] format "->>>>>>>9"
   accum total salesqty[4] format "->>>>>>>9"
   accum total salesqty[5] format "->>>>>>>9"
   accum total salesqty[6] format "->>>>>>>9"
   accum total salesqty[7] format "->>>>>>>9"
   accum total salesqty[8] format "->>>>>>>9"
   accum total salesqty[9] format "->>>>>>>9"
   accum total salesqty[10] format "->>>>>>>9"
   accum total salesqty[11] format "->>>>>>>9"
   accum total salesqty[12] format "->>>>>>>9"
   accum total salesqty[13] format "->>>>>>>9"
   accum total tot_qty format "->>>>>>>>>>9" skip


   accum total salesdol[2] format "->>>>>>>9"
   accum total salesdol[3] format "->>>>>>>9"
   accum total salesdol[4] format "->>>>>>>9"
   accum total salesdol[5] format "->>>>>>>9"
   accum total salesdol[6] format "->>>>>>>9"
   accum total salesdol[7] format "->>>>>>>9"
   accum total salesdol[8] format "->>>>>>>9"
   accum total salesdol[9] format "->>>>>>>9"
   accum total salesdol[10] format "->>>>>>>9"
   accum total salesdol[11] format "->>>>>>>9"
   accum total salesdol[12] format "->>>>>>>9"
   accum total salesdol[13] format "->>>>>>>9"
    accum total tot_dol format "->>>>>>>>>>9" with frame d no-labels
   no-box width 132 STREAM-IO /*GUI*/ .

   if show_profit then display
   accum total salesprft[2] format "->>>>>>>9"
   accum total salesprft[3] format "->>>>>>>9"
   accum total salesprft[4] format "->>>>>>>9"
   accum total salesprft[5] format "->>>>>>>9"
   accum total salesprft[6] format "->>>>>>>9"
   accum total salesprft[7] format "->>>>>>>9"
   accum total salesprft[8] format "->>>>>>>9"
   accum total salesprft[9] format "->>>>>>>9"
   accum total salesprft[10] format "->>>>>>>9"
   accum total salesprft[11] format "->>>>>>>9"
   accum total salesprft[12] format "->>>>>>>9"
   accum total salesprft[13] format "->>>>>>>9"
     accum total tot_prft format "->>>>>>>>>>9" with frame d no-labels
   no-box width 132 STREAM-IO /*GUI*/ .
/*K0L9*/ {wbrp04.i}
